/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define OMEN_SOURCE 1

/// Omen Headers
#include "OmenFactory.h"
#include "OmenKernel.h"
#include "OmenScene.h"
#include "OmenModel.h"
#include "OmenMesh.h"
#include "OmenTimer.h"
#include "OmenMaterial.h"
#include "OmenFileUtils.h"
#include "OmenOctree.h"
#include "OmenCamera.h"
#include "OmenTexture.h"
#include "OmenRigidBody.h"

using namespace Omen;

static std::unique_ptr<IOmenFactory>   pFactoryInstance = NULL;
static std::unique_ptr<IFileUtils>     pFileUtilsInstance = NULL;

/// The default constructor
OmenFactory::OmenFactory()
{
}

///
/// The Factory class factory function
/// Not thread safe
Omen::IOmenFactory& GetOmenFactory() 
{
    return OmenFactory::getFactory();
}

Omen::IOmenFactory& OmenFactory::getFactory()
{
    if( !pFactoryInstance )
        pFactoryInstance = std::unique_ptr<IOmenFactory>(new OmenFactory);
    
    return *pFactoryInstance;
}

IKernel& OmenFactory::getKernel()
{
    return Omen::Kernel::getKernel();
}

// Factory function for creating a new scene object
std::unique_ptr<IScene>  OmenFactory::newSceneObject()
{
    return std::unique_ptr<IScene>(new Omen::Scene());
}

// Factory function for creating a new model object
IModel*  OmenFactory::newModelObject()
{
    return new Omen::Model();
}

// Factory function for creating a new mesh object
IMesh*   OmenFactory::newMeshObject()
{
    return new Omen::Mesh();
}

// Factory function for creating a new mesh object
IMaterial*   OmenFactory::newMaterialObject()
{
    return new Omen::Material();
}

// Factory function for creating a new timer
ITimer* OmenFactory::newTimer()
{
    return new Omen::Timer();
}

// Factory function for creating a new FileUtils object
IFileUtils& OmenFactory::fileUtils()
{
    if( !pFileUtilsInstance )
        pFileUtilsInstance = std::unique_ptr<Omen::IFileUtils>(new Omen::FileUtils);
    return *pFileUtilsInstance;
}

ICamera* OmenFactory::newCamera()
{
    return new Omen::Camera();
}

// Factory function for creating a new texture object
std::unique_ptr<ITexture> OmenFactory::newTextureObject()
{
    return std::unique_ptr<ITexture>( new Omen::Texture );
}

// Factory function for creating a new rigid body object
std::unique_ptr<IRigidBody> OmenFactory::newRigidBody()
{
    return std::unique_ptr<IRigidBody>( new Omen::RigidBody );
}

/// EOF